<template>
    <div>
        <el-card class="box-card" shadow="never">
            <!--导航栏-->
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item>系统设置</el-breadcrumb-item>
                <el-breadcrumb-item>系统日志</el-breadcrumb-item>
            </el-breadcrumb>
            <!--分割线-->
            <div class="yx_line"></div>
            <el-row :gutter="10" style="margin-top:20px;">
                <el-col :span='6'>
                     <el-select v-model="type" placeholder="类型" clearable>
                         <el-option
                                 v-for="item in alltype"
                                 :key="item.value"
                                 :label="item.label"
                                 :value="item.value">
                         </el-option>
                     </el-select>
                </el-col>
            </el-row>
            <el-row :gutter="20" class="yx_el_row">
               <el-col>
                   <el-button type="success" plain @click="search">筛选</el-button>
               </el-col>
            </el-row>
            <el-table class="yx_table" border :data="loglist">
                <el-table-column label="序号" width="100">
                     <template slot-scope="scope">{{(scope.$index+1)+(current_page-1)*20}}</template>
                </el-table-column>
                <el-table-column prop="type" label="日志类型" width="180">
                </el-table-column>
                <el-table-column prop="ip" label="IP地址" width="180">
                </el-table-column>
                <el-table-column prop="content" label="日志内容">
                </el-table-column>
                <el-table-column prop="createTime" label="记录时间">
                </el-table-column>
            </el-table>
            <el-pagination class="yx_page"
                           background
                           @current-change="handle_current_change"
                           @size-change="handle_size_change"
                           :current-page="current_page"
                           :page-sizes="page_sizes"
                           :page-size="page_size"
                           layout="prev, pager, next,sizes, total"
                           :total="total_count">
            </el-pagination>
        </el-card>
    </div>
</template>

<script>
    export default {
        name: 'LogList',
        inject:['reload'],
        data() {
            return {
                alltype:[
                   { label:'登录日志',value:'1'},
                   { label:'同步日志',value:'2'}
                ],
                current_page:1,
                page_size:20,
                type:''
            }
        },
        methods: {
            getList(){
                var send_data={
                    api_token:this.$store.getters.getSessionId,
                    type:this.type==''?-1:this.type,
                    current_page:this.current_page,
                    page_size:this.page_size
                }
                this.$store.dispatch('loadLogList',send_data);
            },
            search(){
                this.current_page=1;
                this.getList();
            },
            //跳转页
            handle_current_change(current_page){
                //当前页码数
                this.current_page=current_page;
                this.getList();
            },
            //修改条数
            handle_size_change(page_size){
                this.current_page=1;
                this.page_size=page_size;
                this.getList();
            }
        },
        created() {
            //加载列表
            this.getList();
        },
        computed:{
            loglist(){
                return this.$store.getters.getLogList;
            },
            total_count(){
                return this.$store.getters.getLogTotalCount;
            },
            page_sizes(){
                return this.$store.state.page_sizes;
            }
        }
    }
</script>

<style>
     @import url('../../assets/css/table.css');
</style>
